package com.qingke.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.qingke.dao.ProductManagementDAO;
import com.qingke.pojo.Product;

@WebServlet("/delete")
public class DeleteServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private ProductManagementDAO dao=new ProductManagementDAO();
       
    public DeleteServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		int id=Integer.valueOf(request.getParameter("id"));
		Product product=dao.selectById(id);
		boolean isSuccess=dao.deleteProduct(product);
		if(isSuccess){
			response.getWriter().write("success");
//			response.getWriter().println("<script>alert('删除成功');window.location.href='list.html';</script>");
		}
		else{
			response.getWriter().write("fail");
//			response.getWriter().println("<script>alert('删除失败');window.history.back();</script>");
		}
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
